/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2014 All Rights Reserved.
 */
package com.h2o3.carmack.message.json;

import com.alibaba.fastjson.JSONObject;
import com.h2o3.carmack.message.Message;

/**
 * @author chensheng
 * @version $Id: JsonMessage.java, v 0.1 1/22/14 10:15 PM chensheng Exp $
 */
public class JsonMessage implements Message {
    private JSONObject jsonObject;

    protected JsonMessage(JSONObject jsonObject) {
        this.jsonObject = jsonObject;
    }

    @Override
    public String getCode() {
        return jsonObject.getString("code");
    }

    @Override
    public <T> T getBody(Class<? extends T> type) {
        return jsonObject.getObject("body", type);
    }

    protected JSONObject getJsonObject() {
        return jsonObject;
    }
}
